﻿Imports System.Data.OleDb

Public Class carupload
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"

        If f_Picture.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("Pictures") & "/" & newFileName
            f_Picture.SaveAs(picLocationOnServerHardDisk)

        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("CarDataString").ConnectionString)
        Dim SqlString As String = "Insert into carclub([Car Make], [Model], [Age], [Engine Size], [Layout], [Origin], [BHP], [Description], [Image]) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_carmake.Text)
        cmd.Parameters.AddWithValue("@f2", tb_model.Text)
        cmd.Parameters.AddWithValue("@f3", tb_age.Text)
        cmd.Parameters.AddWithValue("@f4", tb_engine.Text)
        cmd.Parameters.AddWithValue("@f5", tb_layout.Text)
        cmd.Parameters.AddWithValue("@f6", tb_origin.Text)
        cmd.Parameters.AddWithValue("@f7", tb_bhp.Text)
        cmd.Parameters.AddWithValue("@f8", tb_description.Text)
        cmd.Parameters.AddWithValue("@f9", "Pictures/" & newFileName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub
End Class